package cn.com.dstz.security.encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import cn.com.dstz.utils.ByteTo16String;


public class Md5PwdEncoder{

	public String md5( String md5String ) {
		MessageDigest messagedigest = getMessageDigest( );

		messagedigest.update( md5String.getBytes( ) );

		md5String = new String( ByteTo16String.bufferToHex( messagedigest.digest( ) ) );

		return md5String;
	}

	protected final MessageDigest getMessageDigest( ) {
		String algorithm = "MD5";
		try{
			return MessageDigest.getInstance( algorithm );
		}catch( NoSuchAlgorithmException e ){
			throw new IllegalArgumentException( "No such algorithm ["
					+ algorithm + "]" );
		}
	}

}
